#define DEBUG
#include <cstdio>
#include <cmath>

using namespace std;

typedef long double ld;

const int maxn=100, maxm=300;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

ld sqr(ld a) {
  return a*a;
}

ld calcDis(int x1, int y1, int x2, int y2) {
  return sqrt(sqr(x1-x2)+sqr(y1-y2));
}

bool cross(int a1, int b1, int a2, int b2, int x1, int y1, int x2, int y2) {
  ld k1 = ld(b1-b2)/(a1-a2), k2 = ld(y1-y2)/(x1-x2), o1=b1-a1*k1, o2=y1-x1*k2;
  if (a1==a2 && x1==x2) {
    return a1==x1 && min(b1, b2)<=max(y1, y2) && max(b1, b2)>=min(y1, y2);
  } else if (a1==a2) {
    return k2*a1+o2>=min(b1, b2) && k2*a1+o2<=max(b1, b2);
  } else if (x1==x2) {
    return k1*x1+o1>=min(y1, y2) && k1*x1+o1<=max(y1, y2);
  } else if (k1==k2) {
    return o1==o2 && min(a1, a2)<=max(x1, x2) && max(a1, a2)>=min(x1, x2) && min(b1, b2)<=max(y1, y2) && max(b1, b2)>=min(y1, y2);
  }
  ld p=(o2-o1)/(k1-k2), q=p*k1+o1;
  return p>=min(a1, a2) && p<=max(a1, a2) && p>=min(x1, x2) && p<=max(x1, x2) &&
    q>=min(b1, b2) && q<=max(b1, b2) && q>=min(y1, y2) && q<=max(y1, y2);
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static int p[maxm+1][3], num[maxn+1];
  static ld f[maxm+1][maxm+1];
  for (int i=1; i<=maxm; i++) {
    for (int j=1; j<=maxm; j++) {
      f[i][j] = -1;
    }
  }
  
  int n, m=0;
  scanf("%d", &n);
  for (int i=1, j=1; i<=n; i++) {
    scanf("%d", num+i);
    m += num[i];
    for (int k=1; k<=num[i]; k++, j++) {
      scanf("%d %d", p[j]+1, p[j]+2);
      p[j][0] = i;
      if (k>1) {
	f[j][j-1] = f[j-1][j] = calcDis(p[j][1], p[j][2], p[j-1][1], p[j-1][2]);
      }
    }
    f[j-1][j-num[i]] = f[j-num[i]][j-1] = calcDis(p[j-1][1], p[j-1][2], p[j-num[i]][1], p[j-num[i]][2]);
  }

  for (int i=1; i<=m; i++) {
    for (int j=1; j<=m; j++) {
      if (p[i][0]!=p[j][0]) {
	bool flag=true;
	for (int k=1; k<=m && flag; k++) {
	  int nk= p[k+2][0]==p[k][0] ? k+2 : k+2-num[p[k][0]];
	  if (k!=i && k!=j && nk!=i && nk!=j) {
	    flag = flag && !cross(p[i][1], p[i][2], p[j][1], p[j][2], p[k][1], p[k][2], p[nk][1], p[nk][2]);
	  }
	}
	if (flag) {
	  f[i][j] = f[j][i] = calcDis(p[i][1], p[i][2], p[j][1], p[j][2]);
	}
      }
    }
  }

  for (int k=1; k<=m; k++) {
    for (int i=1; i<=m; i++) {
      if (f[k][i]>=0) {
	for (int j=1; j<=m; j++) {
	  if (f[k][j]>=0) {
	    if ((f[i][j]<0) || (f[i][j]>f[i][k]+f[k][j])) {
	      f[i][j] = f[i][k]+f[k][j];
	    }
	  }
	}
      }
    }
  }

  int s, t;
  scanf("%d %d", &s, &t);
  printf("%.4LF", f[s][t]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
